import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDMissionTrial {
	/**标签页id*/
	id,
	/**标签页名称*/
	name,
	/**任务id*/
	missionId,
	/**主任务奖励*/
	reward,
	/**解锁时间/天*/
	time,
	/**标签页描述*/
	desc,

	/**枚举数量*/
	EnumCount
}



export class CDMissionTrial{
	/**标签页id*/
	public id: number;
	/**标签页名称*/
	public name: number;
	/**任务id*/
	public missionId: number[];
	/**主任务奖励*/
	public reward: number;
	/**解锁时间/天*/
	public time: number;
	/**标签页描述*/
	public desc: number;


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDMissionTrial.id: return this.id;
			case E_CDMissionTrial.name: return this.name;
			case E_CDMissionTrial.missionId: return this.missionId;
			case E_CDMissionTrial.reward: return this.reward;
			case E_CDMissionTrial.time: return this.time;
			case E_CDMissionTrial.desc: return this.desc;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDMissionTrial.id: this.id = v; break;
			case E_CDMissionTrial.name: this.name = v; break;
			case E_CDMissionTrial.missionId: this.missionId = v; break;
			case E_CDMissionTrial.reward: this.reward = v; break;
			case E_CDMissionTrial.time: this.time = v; break;
			case E_CDMissionTrial.desc: this.desc = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDMissionTrial> = new HashMap<number, CDMissionTrial>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDMissionTrial[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDMissionTrial();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].name = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].missionId = [];
			const attrArray = list[i].missionId;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].reward = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].time = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].desc = byte.readInt32();
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDMissionTrial{
		return this.datas ? this.datas.get(id) : null;
	}
}
